﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using chatc_server.database_methods.Database_interface;
using System.Collections;


namespace chatc_server.main
{
    class Main_server

    {
        /// <summary>
        /// This methods creates the server and puts a IServer_Interface object available to be access remotely
        /// by Remoting. With Port 8080
        /// </summary>
        /// <param name="args"></param>

        static void Main(string[] args)
        {
            Console.WriteLine("ChatC Server has been started");


            try
            {
                BinaryServerFormatterSinkProvider serverProv = new BinaryServerFormatterSinkProvider();
                serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;

                BinaryClientFormatterSinkProvider clientProv = new BinaryClientFormatterSinkProvider();

                IDictionary props = new Hashtable();
                props["port"] = 8080;

                TcpChannel tcpChannel = new TcpChannel(props, clientProv, serverProv );
                ChannelServices.RegisterChannel(tcpChannel, false);

                RemotingConfiguration.RegisterWellKnownServiceType(typeof(Server_interface),
                "chatc_server", WellKnownObjectMode.SingleCall);

                System.Console.ReadLine();
            }catch(Exception e) {
                e.StackTrace.ToString();
            }

        }
    }
}
